package com.atech.ebayadmin.category.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.atech.ebayadmin.category.dao.ICategoryDAO;
import com.atech.ebayadmin.category.model.Category;
import com.atech.ebayadmin.common.util.BaseDAOHibernate;

public class CategoryDAO extends BaseDAOHibernate implements ICategoryDAO {
	private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(CategoryDAO.class);
	@Override
	protected Class getObjClass() {
		return Category.class;
	}
    public Category getCategory(String id) throws Exception{
    	Category po = (Category)super.getHibernateTemplate().get(getObjClass(), id);
		return po;
    }
    public List<Category> listCategoryByParentId(String parentId) throws Exception{
		StringBuilder sb = new StringBuilder();
		sb.append("from Category c where c.parentId='").append(parentId).append("'");
		Query query = super.getSession().createQuery(sb.toString());
		return query.list();
    }
    public Integer saveCategory(Category po) throws Exception{
    	Object key = super.getHibernateTemplate().save(po);
    	return (Integer)key;
    }
}
